﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SyncList.Business.Helpers
{

    /// <summary>
    /// Aide sur la gestion des tailles
    /// </summary>
    public static class SizeHelper
    {


        /// <summary>
        /// Formater une taille d'octets
        /// </summary>
        /// <param name="_size"></param>
        /// <returns></returns>
        public static string FormatSize(long size)
        {
            string txt = "";
            double original = size;
            int count = 0;

            while (original >= 1024)
            {

                count++;
                original = original / 1024;
            }

            string unity = "";
            switch (count)
            {
                case 0: unity = "B"; break;
                case 1: unity = "KB"; break;
                case 2: unity = "MB"; break;
                case 3: unity = "GB"; break;
                case 4: unity = "TB"; break;
                case 5: unity = "PB"; break;
                case 6: unity = "EB"; break;
                case 7: unity = "ZB"; break;
                case 8: unity = "YB"; break;
                default:
                    throw new NotSupportedException("Size too big!");
            }

            if (original < 10)
                txt += original.ToString("#0.0");
            else
                txt += original.ToString("#0");

            txt += " " + unity;
            return (txt);
        }
    }
}
